package com.turbo.cloud.core.config;

import com.turbo.cloud.core.trace.TraceInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;

import java.util.List;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> resolvers) {
        //resolvers.add(new GlobalExceptionHandler());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 国际化拦截器
        LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
        localeChangeInterceptor.setParamName("language");
        registry.addInterceptor(localeChangeInterceptor);
        // traceId处理拦截器
        registry.addInterceptor(new TraceInterceptor())
                .addPathPatterns("/api/**")
                .addPathPatterns("/interface/**")
                .addPathPatterns("/webservice/**");
    }
}

